package com.fowo.api.controller.amazon;

import com.fowo.api.common.model.IdPo;
import com.fowo.api.common.model.R;
import com.fowo.api.model.shop.authorization.ShopAuthorizationVo;
import com.fowo.api.service.handleWork.ShopInfoSellerAuthActionImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Tag(name = "亚马逊回调")
@RequestMapping("/api/amazon")
@RestController
public class AmazonRedirectController {

    @Resource
    private ShopInfoSellerAuthActionImpl sellerAuthAction;

    @Operation(summary = "亚马逊登陆验证回调")
    @GetMapping("/loginCallback")
    public R loginCallback(String amazon_callback_uri,String amazon_state,String version,String selling_partner_id) {
        return R.run(() -> sellerAuthAction.loginOauth(amazon_callback_uri,amazon_state,version,selling_partner_id));
    }

    @Operation(summary = "亚马逊回调函数")
    @GetMapping("/callback")
    public R callback(String spapi_oauth_code,String state,String selling_partner_id) {
        return R.run(() -> sellerAuthAction.getRefreshToken(spapi_oauth_code,state,selling_partner_id));
    }

    @Operation(summary = "店铺授权")
    @PostMapping("/createShop")
    public R<String> createShopAuthorizationVo(@RequestBody ShopAuthorizationVo model){
        return R.data(() -> sellerAuthAction.createAuthorization(model));
    }

    @Operation(summary = "刷新授权")
    @PostMapping("/authorization")
    public R<String> getAuthorizationUrl(@RequestBody ShopAuthorizationVo model){
        return R.data(() -> sellerAuthAction.updateAuthorization(model));
    }

}
